
var wh = $(window).height();
$(function(){
	init();
});
function init(){
	e();
	s();
}

var part4Ani = false,part5Ani = false,part6Ani = false;
function e(){
	$(window).scroll(function () {
		// console.log($(this).scrollTop());
		// if (($(this).scrollTop()>(1400-wh)) && ($(this).scrollTop()<2500)) {
		// console.log((1500-1020)*(($(this).scrollTop()-1400+wh)/(2500-1400+wh)));
		// 	$(".part3-bg").css({
		// 		"-webkit-transform":"translateY(-"+(1500-1020)*(($(this).scrollTop()-1400+wh)/(2500-1400+wh))+"px)"
		// 	});	
		// }
		if($(this).scrollTop()>1800){
			if(!part4Ani){
				$(".part4").addClass("active");
				part4Ani = true;
			}
		}else if($(this).scrollTop()<935){
			if(part4Ani){
				$(".part4").removeClass("active");
				part4Ani = false;
			}
		}
		if($(this).scrollTop()>3300){
			if(!part5Ani){
				$(".part5").addClass("active");
				part5Ani = true;
			}
		}else if($(this).scrollTop()<2800){
			if(part5Ani){
				$(".part5").removeClass("active");
				part5Ani = false;
			}
		}

		if($(this).scrollTop()>4300){
			if(!part6Ani){
				$(".part6").addClass("active");
				part6Ani = true;
			}
		}else if($(this).scrollTop()<3500){
			if(part6Ani){
				$(".part6").removeClass("active");
				part6Ani = false;
			}
		}
	});
}

// swiper初始化
function s(){
    // 首页banner
    homeBanner = new Swiper(".homeBanner",{
        slidesPerView: 1,
        autoplay: 3000,
        loop: true,
        pagination : '.homeBanner-pagination',
        paginationClickable :true
    });
    $(".homeBanner").hover(function () {
        homeBanner.stopAutoplay();
    }, function () {
        homeBanner.startAutoplay();
    });
}

//点击发送验证码
$('.btn-send-code').click(function(){
    var phone = $(".input-phone").val();
    if(!phone){
        alert("手机号码不能为空");
        return false;
    }
    if(!(/^1[34578]\d{9}$/.test(phone))){
        alert("手机号码有误");
        return false;
    }
    btnCodeTimeOut();
});

// 验证码60秒倒计时
var codeTime = 60;
function btnCodeTimeOut(){
    $(".btn-code").addClass("off").html(codeTime+"s");
    sms_send();
    var timer = setInterval(function(){
        codeTime--;
        $(".btn-code").html(codeTime+"s");
        if(codeTime < 1){
            clearInterval(timer);
            $(".btn-code").html("获取验证码");
            $(".btn-code").removeClass("off");
            codeTime = 60;
        }
    }, 1000);

}
//发送短信验证码
function sms_send(){
    var mobile = $('.part2 .input-phone').val();
    var regBox = {
        regMobile: /^0?1[3|4|5|7|8][0-9]\d{8}$/, //手机
    };
    var mflag = regBox.regMobile.test(mobile);
    var post = {"phone":mobile,"is_type":2};
    if(mflag){
        $.ajax({
            type: "POST",dataType:"json", url: "index.php?s=user&c=async&m=sms_send", data: post,
            success: function(data) {
                if (data.status) {
                    dr_tips('发送验证码成功....', 3, 1);
                } else {
                    //提示（发送验证次数过多）
                    le_error_message(".le-code>.le-error-message",data.msg);
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                alert(HttpRequest.responseText);
            }
        });
    }else{
        return false;
    }
}


$(".form-btn2").click(function(){
	var name = $(".input-name").val(),
		phone = $(".input-phone").val(),
		code = $(".input-phone-code").val(),
		grade = $("select[name='grade']").val(),
		subject = $("select[name='subject']").val(),
        remark = $(".input-remark").val();
	if(!name){
		alert("姓名不能为空");
		return false;
	}
	if(!phone){
        alert("手机号码不能为空");
        return false;
	}
    if(!(/^1[34578]\d{9}$/.test(phone))){
        alert("手机号码有误");
        return false;
    }
    if(!code){
        alert("验证码不能为空");
        return false;
    }
	if(!grade){
        alert("年级不能为空");
        return false;
	}
	if(!subject){
        alert("科目不能为空");
        return false;
	}
    if(!remark){
        alert("备注不能为空");
        return false;
    }

    if(name&&phone&&grade&&code&&subject&&(/^1[34578]\d{9}$/.test(phone))){

        countLog.init();

        var post = {"name":name,"phone":phone,"grade":grade,"code":code,"subject":subject,"remarke_type":1,'remark':remark};
        $.ajax({
            type: "POST",dataType:"json", url: "index.php?s=mobile&c=home&m=m_source", data: post,
            success: function(data) {
                if (data.status) {
                    // dr_tips('报名成功....', 3, 1);
                    // dr_tips(data.code, 3, 1);
                    // $(".form-btn").attr("disabled", true);
                    $("body>.success-poup-box").fadeIn("slow");
                    $("body>.success-poup-box").delay(2000).fadeOut("slow");
                    setTimeout('window.location.href="'+data.backurl+'"',2000);

                } else {
                    dr_tips(data.code);
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                alert(HttpRequest.responseText);

            }
        });
        // $(".form-btn").attr("disabled", true);
        // $('.form-btn').text("提交完成").css("cssText","background-color: rgb(189, 189, 189);box-shadow: 0px 0px 0px transparent;");
    }

});




$('[name~=grade]').css('color','#9e9e9e');
$('[name~=grade]').change(function() {
    var current = $('[name~=grade]').val();
    if (current != '') {
        $('[name~=grade]').css('color','#333333');
    } else {
        $('[name~=grade]').css('color','#9e9e9e');
    }
});
$('[name~=subject]').css('color','#9e9e9e');
$('[name~=subject]').change(function() {
    var current = $('[name~=subject]').val();
    if (current != '') {
        $('[name~=subject]').css('color','#333333');
    } else {
        $('[name~=subject]').css('color','#9e9e9e');
    }
});

